package MyQueue;

import java.util.LinkedList;
import java.util.Queue;

public class test2 {
    //用双队列实现栈
    private Queue<Integer> A=new LinkedList<>();

    private Queue<Integer> B=new LinkedList<>();

    public void push(int x) {
        A.offer(x);
    }

    public int pop() {
        while(A.size()>1){
            int a=A.poll();
            B.offer(a);
        }
        Queue<Integer> c=A;
        A=B;
        B=c;
        return A.poll();
    }

    public int top() {
        int b=0;
        while(A.size()>0){
            int a=A.poll();
            if(a==1)
                b=a;
            B.offer(a);
        }
        Queue<Integer> f=A;
        A=B;
        B=f;
        return b;
    }

    public boolean empty() {
        return A.isEmpty();
    }
}
